package com.reone.jsbridgedemo.activity;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.widget.TextView;

import com.reone.jsbridgedemo.activity.base.BaseActivity;
import com.reone.jsbridgedemo.utils.LogUtils;
import com.reone.jsbridgedemo.utils.Utils;

import java.util.List;

/**
 * Created by wangxingsheng on 2018/7/16.
 */
public class SecondActivity extends BaseActivity{
    private static final String TAG = SecondActivity.class.getSimpleName();
    private TextView textView;
    private StringBuffer show = new StringBuffer();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
        textView = Utils.newTextView(this,"第二个原生页面,空数据");
        setContentView(textView,param);
        showIntent();
    }

    private void showIntent() {
        appendString(getIntent().toString());
        Uri uri = getIntent().getData();
        if (uri != null) {
            // 完整的url信息
            String url = uri.toString();
            appendString("url: " + url);
            // scheme部分
            String scheme = uri.getScheme();
            appendString("scheme: " + scheme);
            // host部分
            String host = uri.getHost();
            appendString("host: " + host);
            //port部分
            int port = uri.getPort();
            appendString("port: " + port);
            // 访问路劲
            String path = uri.getPath();
            appendString("path: " + path);

            List<String> pathSegments = uri.getPathSegments();
            // Query部分
            String query = uri.getQuery();
            appendString("query: " + query);
            //获取指定参数值
            String goodsId = uri.getQueryParameter("param");
            appendString("goodsId: " + goodsId);
        }
        appendString("data:"+getIntent().getDataString());

        textView.setText(show.toString());
    }

    public void appendString(String text){
        show.append(text);
        show.append("\n");
        LogUtils.d(text);
    }
}
